package com.yanqu.road.server.cmd.activity.chinesechess;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChineseChessProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.chess.ChineseChessPracticeModule;
import com.yanqu.road.server.manger.activity.chinesechess.ChineseChessMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CHINESECHESS_GAME_INFO_PRACTICE, desc = "")
public class ChineseChessIntoPracticeCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ChineseChessProto.ChineseChessIntoPracticeReqMsg reqMsg = ChineseChessProto.ChineseChessIntoPracticeReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(ChineseChessMgr.getShowTimeActivityId() == 0 || ChineseChessMgr.getShowTimeActivityId() != activityId){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        ret = player.getModule(ChineseChessPracticeModule.class).gameInto(activityId);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            ChineseChessProto.ChineseChessIntoPracticeRespMsg.Builder respMsg = ChineseChessProto.ChineseChessIntoPracticeRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_CHINESECHESS_GAME_INFO_PRACTICE, respMsg);
        }
    }
}
